<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js集合之WeakMap</title>
</head>
<body>
  <ul>
    <li>与Map不同的是，WeakMap只能存放引用类型的键值(如数组，对象，DOM节点等)，不能存放基础类型</li>
    <li>WeakMap与Map一样都具备has,set,get,delete等方法,但由于WeakMap的弱引用特性导致不具备size,clear,key(),values(),entries(),遍历等操作</li>
  </ul>
  <script>
    const arr = [1, 2, 3, 4, 5]
    const obj = { name: 'miracle' }
    const dom = document.querySelector('ul')
    const map = new WeakMap()
    // map.set(1, 'number')
    map.set(arr, 'array')
    map.set(obj, 'object')
    map.set(dom, 'dom')
    console.log(map)               // WeakMap {Array(5) => "array", {…} => "object", ul => "dom"}
    console.log(map.get(arr))      // array
    console.log(map.has(arr))      // true
    console.log(map.size)          // undefined
    console.log(map.delete(arr))   // true
    console.log(map)               // WeakMap {{…} => "object", ul => "dom"}
  </script>
</body>
</html>